/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2024-10-11
 * Time: 18:09
 */
public class test3 {
    public static void main(String[] args) {
        System.out.println("3");
    }
    /*
    LeetCode61 旋转链表 给你一个链表的头节点 head ，旋转链表，将链表每个节点向右移动 k 个位置。
     */

    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }
    public ListNode rotateRight(ListNode head, int k) {
        if(k == 0 || head ==null || head.next==null){
            return head;
        }

        //统计链表的长度
        int n =1;
        ListNode cur = head;
        while(cur.next != null){
            cur = cur.next;
            n++;
        }
        //进行次数判断
        int add = n- k%n;
        if(add==n){
            return head;
        }
        cur.next = head;
        while(add>0){
            cur = cur.next;
            add--;
        }
        //拼接
        ListNode ret = cur.next;
        cur.next=null;
        return ret;
    }

}
